package br.unicamp.ic.lis.dbvapi.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import br.unicamp.ic.lis.dbvapi.domain.Scale;
import br.unicamp.ic.lis.dbvapi.service.ScaleService;

public class ScaleServiceImpl extends ServiceImpl<Scale> implements
		ScaleService {

	public ScaleServiceImpl() {
		super(Scale.class);
	}

	@Override
	public Scale getScale(String type, String value) {
		List<Criterion> list = new ArrayList<Criterion>();
		list.add(Restrictions.eq("type", type));
		list.add(Restrictions.eq("value", value));
		return getDAO().findUniqueByCriteria(list);
	}

	@Override
	public List<Scale> getScales(String type) {
		List<Criterion> list = new ArrayList<Criterion>();
		list.add(Restrictions.eq("type", type));
		return getDAO().findByCriteria(list);
	}

	public Scale getParent(Scale scale) {
		if (scale.getParent() == null) {
			return null;
		}
		return getDAO().find(scale.getParent());
	}

	/*
	 * @Override public void setStamp(Dimension dimension) { Dimension parent =
	 * getParent(dimension); String stamp = null; if (parent == null) { stamp =
	 * StringUtils.EMPTY; } // first child else if
	 * (StringUtils.isBlank(parent.getStamp())) { stamp = StringUtils.EMPTY +
	 * dimension.getParent(); } else { stamp = parent.getStamp() +
	 * ConstantsUtils.DOT + dimension.getParent(); }
	 * 
	 * dimension.setStamp(stamp); }
	 */
}
